package com.cloud.bc.controller;

import cn.hutool.core.util.StrUtil;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.service.BcSinglesService;
import com.cloud.bc.service.BcSlideService;
import com.cloud.bc.service.BcUsersService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//单身圈
@AllArgsConstructor
@Controller
@RequestMapping("m/moment")
public class MomentController extends BaseController {
    private final BcSlideService bcSlideService;
    private final BcUsersService bcUsersService;
    private final BcSinglesService bcSinglesService;

    /**
     * 单身圈首页
     */
    @GetMapping("")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
        String orderBy = request.getParameter("orderBy");
        ModelAndView view = baseView(request,"单身圈", "m/moment/index");
        UserInfo userInfo = bcUsersService.getUserInfo(request);
        boolean isVip = bcSinglesService.isVip(userInfo);
        if (StrUtil.isEmpty(orderBy)) {
            //只有推荐页才显示滑动页
            view.addObject("slide", bcSlideService.selectAll(null));
        }
        view.addObject("orderBy", orderBy);
        view.addObject("isVip", isVip);
        return view;
    }

    /**
     * 创建动态
     */
    @GetMapping("create")
    public ModelAndView create(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request,"创建动态", "m/moment/create");
        String mediaType = request.getParameter("media_type");
        //默认是图片动态
        mediaType = StrUtil.isEmpty(mediaType) ? "image" : mediaType;
        view.addObject("mediaType", mediaType);
        return view;
    }
}
